﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GGJ_DKG.Managers
{
    static class SoundManager
    {

        static Dictionary<String, Song> listMusic = new Dictionary<String, Song>();
        static Dictionary<String, SoundEffect> listSoundEffect = new Dictionary<String, SoundEffect>();

        static private string Playing;

        static public float GeneralVolume = 1;
        static public float EffectVolume = 1;

        static public void AddMusic(String name, Song music)
        {

            listMusic.Add(name, music);

        }

        static public void PlayMusic(String name)
        {
            MediaPlayer.Play(listMusic[name]);
            Playing = name;

        }

        static public bool CheckSong(String name)
        {
            if (MediaPlayer.State == MediaState.Playing
                && Playing == name)
            {
                return true;
            }

            return false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">SoundEffect or Music</param>
        /// <param name="name">File name</param>
        /// <returns></returns>
        static public bool CheckList(String type, String name)
        {
            if (type == "SoundEffect")
                return listSoundEffect.ContainsKey(name);
            if(type == "Music")
                return listMusic.ContainsKey(name);
            return false;
        }

        static public void AddSound(String name, SoundEffect sound)
        {
            listSoundEffect.Add(name, sound);
        }

        static public void PlaySound(String name)
        {
            SoundEffectInstance soundEffectInstance = listSoundEffect[name].CreateInstance();
            soundEffectInstance.Play();
        }

        static public void StopMusic()
        {
            Playing = "none";
            MediaPlayer.Stop();
        }

        static public void LowerVolume(float volume)
        {
            MediaPlayer.Volume -= volume;
        }

        static public void RaiseVolume(float volume)
        {
            MediaPlayer.Volume += volume;
        }

    }
}